package cc.lishixi.app001;

import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.collections.immutable.ImmutableList;
import org.apache.pivot.wtk.*;

import java.io.File;

class MyWindow extends Window {
    private MyWindow win;

    MyWindow() {
        win = this;
        Border border = new Border();
        border.getStyles().put("padding", 6);
        TablePane.Column column = new TablePane.Column();
        column.setWidth("1*");
        Sequence<TablePane.Column> columns = new ArrayList<TablePane.Column>();
        columns.add(column);
        TablePane tablePane = new TablePane(columns);

        TablePane.Row row = new TablePane.Row();
        row.setHeight("1*");
        TablePane.Row row1 = new TablePane.Row(30);

        tablePane.getRows().add(row);
        tablePane.getRows().add(row1);
        StyleDictionary styles = tablePane.getStyles();
        styles.put("verticalSpacing", 1);
        styles.put("showHorizontalGridLines", true);
        styles.put("horizontalSpacing", 1);
        styles.put("showVerticalGridLines", true);

        final FileBrowser fileBrowser = new FileBrowser(new File(".").getAbsolutePath());

        boolean showing = fileBrowser.isShowing();
        System.out.println("showing = " + showing);
        fileBrowser.getFileBrowserListeners().add(new FileBrowserListener.Adapter() {
            @Override
            public void selectedFileAdded(FileBrowser fileBrowser, File file) {
                System.out.println("fileBrowser = " + fileBrowser);
                File selectedFile = fileBrowser.getSelectedFile();
                System.out.println("selectedFile = " + selectedFile);
            }
        });


        BoxPane buttons = new BoxPane(Orientation.HORIZONTAL);
        buttons.getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
        buttons.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);

        PushButton ok = new PushButton("OK");
        ok.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                ImmutableList<File> selectedFiles = fileBrowser.getSelectedFiles();
                System.out.println("selectedFiles = " + selectedFiles);
                win.close();
            }
        });

        buttons.add(ok);
        PushButton btnCancel = new PushButton("Cancel");
        btnCancel.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {

            }
        });
        buttons.add(btnCancel);

        row.add(fileBrowser);
        row1.add(buttons);

        border.setContent(tablePane);
        setContent(border);
    }
}
